package com.prj.ufdm.auth.security;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Service;

import com.prj.ufdm.auth.enums.AuthRetCodeEnum;
import com.prj.ufdm.core.dto.RetData;
import com.prj.ufdm.core.util.UfdmRequestUtil;
import com.alibaba.fastjson.JSON;

/**
 * 身份认证异常处理
 * @author Administrator
 */
@Service
public class ExpAuthenticationHandleImpl implements AuthenticationEntryPoint{
	
	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,AuthenticationException authException) throws IOException {
		
		System.out.println("未登录.......");
		UfdmRequestUtil.addCsrfHeader(response);
		RetData<String> retData = new RetData<>();
		retData.getRetHead().setCode(AuthRetCodeEnum.RET_CODE_0101001.getCode());
		retData.getRetHead().setMessage(AuthRetCodeEnum.RET_CODE_0101001.getMessage());
		response.getWriter().write(JSON.toJSONString(retData));
	}
	
}
